package au.com.ecaporali.module1.introexercises.diamond;

/**
 * Created by Enrico on 7/09/2014.
 */
public class Diamond {

    private static final String STAR = "*";
    private static final String SPACE = " ";

    public void isosceles(int number){
        for(int i = 1, stars = 1; i <= number; i++, stars+=2){
            int spaces = number - i;
            showLine(spaces,stars);
        }
    }

    public void diamond(int number){
        upperTriangle(number);
        //showLine(0, number);
        showName("Enrico");
        lowerTriangle(number);
    }

    private void upperTriangle(int number){
        for(int stars = 1; stars < number; stars+=2){
            int spaces = spaceCalculator(number,stars);
            showLine(spaces,stars);
        }
    }

    private void lowerTriangle(int number){
        for(int stars = number-2; stars > 0; stars-=2){
            int spaces = spaceCalculator(number,stars);
            showLine(spaces,stars);
        }
    }

    private void showLine(int spaces, int stars){
        showLine(spaces, this.SPACE);
        showLine(stars, this.STAR);
        System.out.println();
    }


    private void showLine(int n, String s){
        for (int i = 0; i < n; i++){
            System.out.print(s);
        }
    }

    private int spaceCalculator(int max, int stars){
        return (max - stars) / 2;
    }

    private void showName(String name){
        System.out.println(name);
    }
}
